package app 
{
	import com.bit101.components.VBox;
	import fl.controls.Button;
	import fl.controls.Label;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import gui.factory.StyleFactory;
	import gui.NumStepper;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class ModuleRoomSize extends Sprite
	{
		private var _sliderLen:NumStepper;
		private var _sliderWidth:NumStepper;
		private var _sliderHeight:NumStepper;
	
		private var _model:AppModel;
		private var _vbox:VBox;
		
		/**
		 * If size in mm set value 10, for centimeters = 1;
		 */
		private var _sizeFactor:Number = 10;
		
		public function ModuleRoomSize(model:AppModel) 
		{
			_sizeFactor = _sizeFactor * AppSettings.SCALE_FACTOR;
			
			_model = model;
			addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
		}
		
		private function handleAddedToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
			
			initModule();
		}
		
		private function initModule():void 
		{
			this.x = 102;
			this.y = 14;
			var bgMovie:DisplayObject = new RoomSizeBg();
			addChild(bgMovie);
					
			_vbox = new VBox(this, 21, 128);
			_vbox.spacing = 80;
			
			_sliderLen = createSlider();
			_sliderWidth = createSlider();
			_sliderHeight = createSlider();
			
			_sliderLen.x = 30;
			_sliderLen.y = 128;
			addChild(_sliderLen);
			
			_sliderWidth.x = 30;
			_sliderWidth.y = 208;
			addChild(_sliderWidth);
			
			_sliderHeight.x = 30;
			_sliderHeight.y = 288;
			addChild(_sliderHeight);
			
			_sliderWidth.valueNum = _model.roomWidth / _sizeFactor;
			_sliderLen.valueNum = _model.roomLength / _sizeFactor;
			_sliderHeight.valueNum = _model.roomHeight / _sizeFactor;
			
			_sliderWidth.addEventListener("change", handleSliderChange);
			_sliderLen.addEventListener("change", handleSliderChange);
			_sliderHeight.addEventListener("change", handleSliderChange);
			//handleSliderChange(null);
		}
		
		
		private function createSlider():NumStepper
		{
			var numStep:NumStepper = new NumStepper();
			StyleFactory.setNumStepStyle(numStep, StyleFactory.NUM_STEP_ROOM_SIZE);
			numStep.min = 150;
			numStep.max = 500;
			numStep.step = 1;
			return numStep;
		}
		
		private function handleSliderChange(e:Event):void 
		{
			//_txtLen.text = _sliderLen.valueNum.toString();
			//_txtWidth.text = _sliderWidth.valueNum.toString();
			//_txtHeight.text = _sliderHeight.valueNum.toString();
			_model.roomWidth = _sliderWidth.valueNum * _sizeFactor;
			_model.roomLength = _sliderLen.valueNum * _sizeFactor;
			_model.roomHeight = _sliderHeight.valueNum * _sizeFactor;
		}
		
	}

}